package com.lsh.oms.core.model.order;

import com.lsh.base.lang.Exceptions;
import com.lsh.base.lang.json.Jsons;
import com.lsh.oms.core.model.base.VenderModel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Map;

/**
 * 订单明细扩展信息
 *
 * @author huangdong
 * @date 16/8/1
 */
@Setter
@Getter
@ToString
@NoArgsConstructor
public class OrderDetailExt extends VenderModel implements Serializable {

    private static final long serialVersionUID = -5095622315274076920L;

    /**
     * ID
     */
    private Long id;

    /**
     * 用户ID
     */
    private Long uid;

    /**
     *
     */
    private String imgList;

    /**
     * 实际订购数量
     */
    private BigDecimal realQty;

    /**
     * 单个优惠金额
     */
    private BigDecimal discountPrice;

    /**
     * 下单单价（优惠后）
     */
    private BigDecimal placedPrice;

    /**
     * 优惠总额
     */
    private BigDecimal couponMoney;

    /**
     * 下单总额(优惠后)
     */
    private BigDecimal placedMoney;

    /**
     * 当前总额
     */
    private BigDecimal money;

    /**
     * 1-有效
     */
    private Integer status;

    /**
     * 活动信息{["activity_id":"","activity_name":"","coupon_money":""]}
     */
    private String activityInfo;

    /**
     * 优惠券信息{["coupon_id":"", "coupon_name":"", "coupon_money":""]}
     */
    private String couponInfo;

    /**
     * 赠品信息
     */
    private String giveInfo;

    /**
     * 额外信息
     */
    private String ext;

    /**
     * 调度系统ID
     */
    private Long ofcId;

    /**
     * 调度状态
     */
    private Integer ofcStatus;

    /**
     *
     */
    private String orderPackageInfo;

    /**
     * 所属地域id
     */
    private Integer zoneId;

    /**
     * 是否黑名单商品, 0否, 1不参与计算优惠
     */
    private Integer isBlacklist;
    /**
     * 是否有发票, 0无发票, 1有发票
     */
    private Integer isInvoice;
    /**
     * 发票费率类型, 1为0%, 2为13%, 3为17%
     */
    private Integer invoiceRate;

    /**
     * 用于价格计算
     */
    private BigDecimal cutPromotionMoney;
    /**
     * 用于价格计算
     */
    private BigDecimal ticketCouponPromotionMoney;

    public Map<String, Object> orderPackageInfo() {
        try {
            return StringUtils.isNotBlank(orderPackageInfo) ? Jsons.fromJsonString(orderPackageInfo) : Collections.emptyMap();
        } catch (Exception e) {
            Exceptions.printStackTraceLineByLine(e);
        }
        return Collections.emptyMap();
    }
}
